<template>
  <div class="like">
    <div class="title">
      <van-divider dashed>
        <p class="icon-xihuancopy iconfont"></p>
        <span>猜你喜欢</span>
      </van-divider>
    </div>
    <!-- <div class="pro_item" v-for="(item, index) in list" :key="index">
        <div class="img">
          <van-image class="pro_item_img" :src="item.img">
            <template v-slot:loading>
              <van-loading type="spinner" size="20" />
            </template>
          </van-image>
        </div>
        <span class="ellipsis-2">{{ item.pro_name }}</span>
        <div class="bot">
          <span class="price">￥ {{ item.price }}.00</span>
          <p class="icon-gouwugouwuchedinggou iconfont"></p>
        </div>
      </div> -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="已经到底了，地主家已经没有余粮了~~"
      @load="onLoad"
    >
      <div class="pro_list">
        <div class="pro_item" v-for="item in list" :key="item.id">
          <div class="img">
            <van-image class="pro_item_img" :src="item.photo">
              <template v-slot:loading>
                <van-loading type="spinner" size="20" />
              </template>
            </van-image>
          </div>
          <span class="ellipsis-2">{{ item.title }}</span>
          <div class="bot">
            <span class="price">￥ {{ item.price }}</span>
            <p class="icon-gouwugouwuchedinggou iconfont"></p>
          </div>
        </div>
      </div>
    </van-list>
    <!-- <div class="foot">
      <van-divider dashed>
        <p class="icon-tuiguang iconfont"></p>
        <span>已经到底了，地主家已经没有余粮了~~</span>
      </van-divider>
    </div> -->
  </div>
</template>

<script>
import { reqLiskApi } from "@/services";
export default {
  name: "like",
  data() {
    return {
      list: [],
      page: 1,
      size: 6,
      loading: false,
      finished: false,
    };
  },
  methods: {
    async onLoad() {
      // 异步更新数据
      const { page, size } = this;
      const res = await reqLiskApi(page, size);
      if (res.code === 200) {
        const { list, page, total } = res.data;
        // console.log(res.data.list);
        this.list.push(...list);
        if (page >= total) {
          // 加载状态结束
          this.finished = true;
          return;
        }
        this.page++;
      }
      this.loading = false;
      // console.log(res);
    },
  },
};
</script>

<style lang="less" scoped>
.like {
  .title {
    width: 100%;
    p {
      font-size: 30px;
      margin-right: 20px;
    }
  }
  .pro_list {
    display: flex;
    flex-wrap: wrap;
    padding: 0 40px;
    justify-content: space-between;
    .pro_item {
      width: 320px;
      height: 406px;
      margin-top: 20px;

      background-color: #fff;
      .img {
        width: 100%;
        height: 310px;
        // border: 1px solid red;
        .pro_item_img {
          width: 100%;
          height: 100%;
        }
      }
      span {
        font-size: 18px;
        line-height: 25px;
        height: 50px;
        margin-top: 10px;
      }
      .bot {
        display: flex;
        justify-content: space-between;
        span {
          color: red;
          font-size: 18px;
          font-weight: bold;
        }
        p {
          margin-right: 15px;
          font-size: 30px;
          color: #08dbdb;
          margin-top: 5px;
        }
      }
    }
  }
  .foot {
    width: 100%;
    float: left;
    p {
      font-size: 30px;
      margin-right: 20px;
    }
  }
}
</style>
